﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace VitCode.BaseDataPageCreator
{
    public class UrlHelper
    {
        public static string GetHttpHeadPath()
        {
            var reVal = "";
            if(HttpContext.Current != null)
            {
                var rq = HttpContext.Current.Request;
                reVal = rq.Url.Scheme + "://" + rq.Url.Host;
                if (rq.Url.Port != 80)
                    reVal = reVal + ":" + rq.Url.Port;
                reVal = reVal + rq.ApplicationPath;
            }
            return reVal;
        }

        public static string GetVirtualPath()
        {
            var reVal = "";
            if (HttpContext.Current != null)
            {
                var rq = HttpContext.Current.Request;
                var abPath = rq.Url.AbsolutePath;
                var appPath = rq.ApplicationPath;
                if (!String.IsNullOrEmpty(appPath) && abPath.StartsWith(appPath))
                    reVal = abPath.Remove(0, appPath.Length);
                else
                    reVal = appPath;
            }
            return reVal;
        }
    }
}
